package com.fortest;

import org.apache.commons.fileupload.util.Streams;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Test9 {
    public static void main(String[] args){
        try {
            downloadPicture("http://aimgs.oss-cn-shenzhen.aliyuncs.com/jztk/2017/subject4/4065.jpg",
                    "E:\\毕设有关\\上传的文件\\java下载的图片\\","test2.jpg");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void downloadPicture(String urlString,String save_path,String filename) throws IOException {
        URL url = new URL(urlString);
        // 打开连接
        URLConnection con = url.openConnection();
        // 输入流
        InputStream is = con.getInputStream();
        // 1K的数据缓冲
        File file = new File(save_path+filename);
        FileOutputStream os = new FileOutputStream(file, true);
        Streams.copy(is,os,true);
    }
}
